package com.ygqh.baby.model;

import com.ygqh.baby.constant.RedisConstant;
import com.ygqh.baby.utils.ShareCodeUtil;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;

/**
 * @Author: sunshuo
 * @Date: 2019/6/17/017 13:28
 * @Version: 1.0
 */
public class ShareProductImageReq {

    /**
     * 分享类型
     */
    private ShareType shareType;

    /**
     * 分享用户id
     */
    private Long shareUserId;

    /**
     * 平台编号
     */
    private String platformNo;

    /**
     * 商品id
     */
    private Long productId;

    /**
     * 目标价格
     */
    private BigDecimal targetPrice;

    /**
     * 首行信息
     */
    private String headMessage;

    /**
     * 价格标题
     */
    private String priceMessage;

    /**
     * 价格前缀
     */
    private String pricePrefix;

    /**
     * 尾部信息
     */
    private String footMessage;

    /**
     * 落地页地址
     */
    private String floorPage;

    public ShareType getShareType() {
        return shareType;
    }

    public void setShareType(ShareType shareType) {
        this.shareType = shareType;
    }

    public Long getShareUserId() {
        return shareUserId;
    }

    public void setShareUserId(Long shareUserId) {
        this.shareUserId = shareUserId;
    }

    public String getPlatformNo() {
        return platformNo;
    }

    public void setPlatformNo(String platformNo) {
        this.platformNo = platformNo;
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public BigDecimal getTargetPrice() {
        return targetPrice;
    }

    public void setTargetPrice(BigDecimal targetPrice) {
        this.targetPrice = targetPrice;
    }

    public String getHeadMessage() {
        if (StringUtils.isBlank(headMessage) && (shareType == null || ShareType.OrdinaryProduct.equals(shareType))) {
            return "长按识别有优惠 一定要看呀~";
        }
        return headMessage;
    }

    public void setHeadMessage(String headMessage) {
        this.headMessage = headMessage;
    }

    public String getPriceMessage() {
        return priceMessage;
    }

    public void setPriceMessage(String priceMessage) {
        this.priceMessage = priceMessage;
    }

    public String getPricePrefix() {
        if (StringUtils.isBlank(pricePrefix) && (shareType == null || ShareType.OrdinaryProduct.equals(shareType))) {
            return "仅需:";
        }
        return pricePrefix;
    }

    public void setPricePrefix(String pricePrefix) {
        this.pricePrefix = pricePrefix;
    }

    public String getFootMessage() {
        if (StringUtils.isBlank(footMessage) && (shareType == null || ShareType.OrdinaryProduct.equals(shareType))) {
            return "长按识别领福利";
        }
        return footMessage;
    }

    public void setFootMessage(String footMessage) {
        this.footMessage = footMessage;
    }

    public String getFloorPage() {
        if (StringUtils.isBlank(floorPage) && (shareType == null || ShareType.OrdinaryProduct.equals(shareType))) {
            return "pages/goods/detail/detail?productId=" + productId +
                    "&sourceCode=" + ShareCodeUtil.toSerialCode(shareUserId);
        }
        return floorPage;
    }

    public void setFloorPage(String floorPage) {
        this.floorPage = floorPage;
    }

    @Override
    public String toString() {
        return "ShareProductImageReq{" +
                "shareType=" + shareType +
                ", shareUserId=" + shareUserId +
                ", platformNo='" + platformNo + '\'' +
                ", productId=" + productId +
                ", targetPrice=" + targetPrice +
                ", headMessage='" + headMessage + '\'' +
                ", priceMessage='" + priceMessage + '\'' +
                ", pricePrefix='" + pricePrefix + '\'' +
                ", footMessage='" + footMessage + '\'' +
                ", floorPage='" + floorPage + '\'' +
                '}';
    }

    public String getRedisKey() {
        return String.format(RedisConstant.YIJIADIAN_USER_SHARE_PRODUCT_PREFIX_KEY,
                shareType == null ? ShareType.OrdinaryProduct : shareType, shareUserId, productId);
    }

    public static enum ShareType {
        OrdinaryProduct, GroupProduct, CutProduct, UserCenter;
    }
}
